class util{
        //get请求参数校验
        get_check_data(check=[],req){
            const checkData  = check //自定义校验接口必传参数  type:Array
            let returnData = {
                pass:true,
                msg:''
            }
            if(checkData.length!=0){
                let str = '缺少'
                for (let index = 0; index < checkData.length; index++) {
                    if(!req.query[checkData[index]]){
                        str += `${ checkData[index] }${ index!=checkData.length-1?'、':'' }`
                    }
                }
                if(str!=='缺少'){
                    returnData.pass = false;
                    returnData.msg = str
                }
            }

            return returnData;
        }
        //post请求参数校验
        post_check_data(check=[],req){
            const checkData  = check //自定义校验接口必传参数 type:Array
            let returnData = {
                pass:true,
                msg:''
            }
            if(checkData.length!=0){
                let str = '缺少'
                for (let index = 0; index < checkData.length; index++) {
                    if(!req.body[checkData[index]]){
                        str += `${ checkData[index] }${ index!=checkData.length-1?'、':'' }`
                    }
                }
                if(str!=='缺少'){
                    returnData.pass = false;
                    returnData.msg = str
                }
            }

            return returnData;
        }

        //时间戳转换
         rTime(date) { var json_date = new Date(date).toJSON();
            return new Date(+new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '') 
        }
}

module.exports =  new util()